package com.hdu.joinInMemory.repository;

import com.hdu.joinInMemory.entity.DO.Address;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Repository
public class AddressRepository {

    private static final List<Address> ADDRESSES = new ArrayList<>();

    static {
        for (long i = 0; i < 100; i++) {
            long j = i + 1;
            ADDRESSES.add(new Address(j, j, "address--" + j));
        }
    }

    public List<Address> findAddressById(List<Long> id) {
        return ADDRESSES.stream().filter(address -> id.contains(address.getId())).collect(Collectors.toList());
    }

    public Address findAddressById(Long userId) {
        return ADDRESSES.stream().filter(address -> address.getUserId().equals(userId)).collect(Collectors.toList()).get(0);
    }
}
